<template>
    <div class="app-container">
        <!-- UserPoliAppl RelatedCases-->
        <!-- 用户导入对话框 -->
        <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
            <el-upload
                ref="uploadRef"
                :limit="1"
                accept=".xlsx, .xls"
                :headers="upload.headers"
                :action="upload.url + '?updateSupport=' + upload.updateSupport"
                :disabled="upload.isUploading"
                :on-progress="handleFileUploadProgress"
                :on-success="handleFileSuccess"
                :auto-upload="false"
                drag
            >
                <el-icon class="el-icon--upload">
                    <upload-filled/>
                </el-icon>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                <template #tip>
                        <div class="el-upload__tip">
                            <el-checkbox v-model="upload.updateSupport" style="margin-right: 5px;"/>
                            <span>是否更新已经存在的用户数据</span>
                        </div>
                        <div>
                            <span>仅允许导入xls、xlsx格式文件。</span>
                            <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                                    @click="importTemplate">下载模板
                            </el-link>
                        </div>
                </template>
            </el-upload>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submitFileForm">确 定</el-button>
                    <el-button @click="upload.open = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>
        <el-form ref="queryParamsRef" :inline="true" label-width="100" :model="queryParams">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-form-item label="律所名称-司法局共享信息">
                        <el-input v-model="queryParams.casecode" clearable @clear="getTableDataLists" style="width: 13vw;"/>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="律师名称">
                        <el-input v-model="queryParams.name" 
                        clearable 
                        @clear="getTableDataLists" 
                        @keyup.enter.prevent="getTableDataLists"
                        style="width: 13vw;"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="案件名称">
                        <el-input v-model="queryParams.name" 
                        clearable 
                        @clear="getTableDataLists" 
                        @keyup.enter.prevent="getTableDataLists"
                        style="width: 13vw;"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="预出库日期">
                        <el-date-picker
                            v-model="dateRange"
                            value-format="YYYY-MM-DD"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            style="width:13vw"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item>
                        <el-button type="primary" @click="getTableDataLists">
                            <el-icon class="me-1">
                                <Search/>
                            </el-icon>
                            查询
                        </el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="handleRest">
                            <el-icon class="me-1">
                                <Refresh/>
                            </el-icon>
                            重置
                        </el-button>
                    </el-form-item>
                </el-col>
                
            </el-row>
        </el-form>
        <el-divider class="mt-0 mb-3"/>
        <el-row class="mb-3">
            <el-col :span="24">
                <el-space>
                    <el-button
                            type="info"
                            plain
                            icon="Upload"
                            @click="handleImport"
                            v-hasPermi="['system:user:import']"
                        >导入
                        </el-button>
                </el-space>
            </el-col>
        </el-row>
        <el-table
            v-loading="loading"
            :data="TablesData"
            show-overflow-tooltip
        >
            <el-table-column label="律所名称" prop="name"/>
            <el-table-column label="律师名称" prop="casetype"/>
            <el-table-column label="执业证号" prop="userName"/>
            <el-table-column label="联系电话" prop="userName"/>
            <el-table-column label="案件名称" prop="userName"/>
            <el-table-column label="受理日期" prop="userName"/>
            <el-table-column label="嫌疑人" prop="casetype"/>
            <el-table-column label="身份证号" prop="casetype"/>
        </el-table>
        <pagination
            v-show="total > 0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getTableDataLists"
        />
    </div>
</template>

<script setup>
const {proxy} = getCurrentInstance();
// import {getCaseInfoList,getCaseInfoInfo,  deleteCaseInfo} from "@/api/CaseInfo/CaseInfo";
import PageEnum from "@/enum/PageEnum.js";
import {getToken} from "@/utils/auth";

const {sys_normal_disable,nj_anjian_status} = proxy.useDict('sys_normal_disable', 'nj_anjian_status')

const queryParamsRef = ref()
const loading = ref(false)
const dateRange = ref([])

const queryParams = ref({
    name: '',
    casecode: '',
     // 页码
     pageNum: 1,
    // 分页数量
    pageSize: PageEnum.SIZE
})

const total = ref(0)
const TablesData = ref([{
    name:'111',
}])
/*** 用户导入参数 */
const upload = reactive({
    // 是否显示弹出层（用户导入）
    open: false,
    // 弹出层标题（用户导入）
    title: "",
    // 是否禁用上传
    isUploading: false,
    // 是否更新已经存在的用户数据
    updateSupport: 0,
    // 设置上传的请求头部
    headers: {Authorization: "Bearer " + getToken()},
    // 上传的地址
    url: import.meta.env.VITE_APP_BASE_API + "/system/user/importData"
 });
onMounted(() => {
    // getTableDataLists()
})

// 获取案件列表
const getTableDataLists = async () => {
    proxy.$modal.msgSuccess("获取案件");
    // loading.value = true
    // await getCaseInfoList(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    //     loading.value = false;
    //     TablesData.value = res.rows
    //     total.value = res.total;
    // });
}

 /** 提交上传文件 */
 function submitFileForm() {
    proxy.$refs["uploadRef"].submit();
 }
 /** 导入按钮操作 */
 function handleImport() {
    upload.title = "预出库条码导入";
    upload.open = true;
 }
  /**文件上传中处理 */
  const handleFileUploadProgress = (event, file, fileList) => {
    upload.isUploading = true;
 };
  /** 文件上传成功处理 */
  const handleFileSuccess = (response, file, fileList) => {
    upload.open = false;
    upload.isUploading = false;
    proxy.$refs["uploadRef"].handleRemove(file);
    proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
    getList();
 };
  /** 下载模板操作 */
  function importTemplate() {
    proxy.$modal.msgSuccess("下载模版");
 }
// 重置搜索调解
const handleRest = () => {
    queryParams.value = {
        name: '',
        casecode: '',
    }
    getTableDataLists()
}
</script>

<style scoped>
.el-upload__tip{display: flex;display: -webkit-flex;align-items: center;}
</style>